

#ifndef __FAT_FS_H__
#define __FAT_FS_H__




typedef struct _tag_sdcontext {

	cvi_sdhc_regs_t * psdhc;

	/* sdsc(<= 2G),  sdhc(<= 32G) */
	int scflag;			/* 0 - sdhc, other=sdsc(2G) */

	/* 容量单位使用 sector, 512 字节 */
	uint64_t capacity;

} sdctx_t;




typedef struct _tag_fatfs {

	sdctx_t * psdc;

	uint32_t sttlba;		/* 分区开始位置, 扇区单位. */
	uint32_t totals;        /* 分区内总的扇区数. */

	uint32_t clusiz;		/* sectors per cluster */
	
	uint32_t fatofs;		/* offset from PartitionStart */
	uint32_t fatsiz;		/* fat table sectors */
	
	uint32_t rdrofs;		/* offset from PartitionStart */
	uint32_t rdrsiz;		/* root directory sectors */
	
	uint32_t datofs;		/* offset from PartitionStart */

} fatfs_t;



int sdcard_init( uintptr_t shbase, sdctx_t * pctx );
int sdcard_read_single( sdctx_t * pctx, uint32_t sidx, void * pary );

int fatfs_init( sdctx_t * psdc, fatfs_t * pfatfs );
int fatfs_fstat( fatfs_t * pfatfs, const char * fname, uint32_t * psiz );
int fatfs_fread( fatfs_t * pfatfs, const char * fname, uint8_t * ptr );


#endif

